﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL;
using System.Web.Security;

namespace WebUI
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string Name = "";
                string role = Request.Cookies["role"].Value;
                switch (role)
                {
                    case "admin":
                        AdminUser u = AdminUserManage.SelectUserByUsername(User.Identity.Name);
                        Name = u.name;
                        XmlDataSource1.DataFile = "~/AdminMenu.xml";
                        break;
                    case "student":
                        Model.Users us = UsersManage.SelectByUsername(User.Identity.Name);
                        Name = us.name;
                        XmlDataSource1.DataFile = "~/StudentMenu.xml";
                        break;
                    case "teacher":
                        Model.Users ut = UsersManage.SelectByUsername(User.Identity.Name);
                        Name = ut.name;
                        XmlDataSource1.DataFile = "~/TeacherMenu.xml";
                        break;
                }
                tbtWelcome.Text = "欢迎您，"+ Name;
                // 绑定 XML 数据源到树控件
                treeMenu.DataSource = XmlDataSource1;
                treeMenu.DataBind();
            }
        }

        protected void btnLogout_Click(object sender, EventArgs e)
        {
            FormsAuthentication.SignOut();
            FormsAuthentication.RedirectToLoginPage();
            Response.Cookies["role"].Expires = DateTime.Now.AddDays(-1); 
        }
    }
}